<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Builder;

/**
 * App\Models\Account
 *
 * @property int $id
 * @property int $user_id
 * @property string|null $type
 * @property string|null $money
 * @property string|null $reason
 * @property string|null $data
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read \App\Models\User $user
 * @method static \Database\Factories\AccountFactory factory(...$parameters)
 * @method static \Illuminate\Database\Eloquent\Builder|Account newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Account newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Account query()
 * @method static \Illuminate\Database\Eloquent\Builder|Account whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Account whereData($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Account whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Account whereMoney($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Account whereReason($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Account whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Account whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Account whereUserId($value)
 * @mixin \Eloquent
 * @property string|null $remark
 * @method static \Illuminate\Database\Eloquent\Builder|Account whereRemark($value)
 * @property string|null $origin
 * @method static \Illuminate\Database\Eloquent\Builder|Account whereOrigin($value)
 * @property string|null $result
 * @method static \Illuminate\Database\Eloquent\Builder|Account whereResult($value)
 */
class Account extends Model
{
    use HasFactory;
	
	protected $guarded = ['id'];
	
	protected $casts = [
		'data' => 'json'
	];

    public function scopePay(Builder $builder): Builder
    {
        return $builder->where('money', '<' , 0);
    }

    public function scopeIncome(Builder $builder): Builder
    {
        return $builder->where('money', '>' , 0);
    }
	
	public function user()
	{
		return $this->belongsTo(User::class, 'user_id', 'id');
	}
}
